package ocrs.client;


import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasVerticalAlignment;



public class LoginPage extends Composite {

	private TextBox textBoxUsername;
	private PasswordTextBox textBoxPassword;
	
	public LoginPage() {
	
		AbsolutePanel basePanel = new AbsolutePanel();
		basePanel.setStyleName("gwt-VerticalPanel-ocrsLogin");
		basePanel.setSize("450px", "300px");
		initWidget(basePanel);
		
		Label lblSignInTo = new Label("Sign in to your account");
		lblSignInTo.setStyleName("gwt-Label-ocrsWhite");
		//lblSignInTo.setStyleName("gwt-Label-Login");
		basePanel.add(lblSignInTo, 0, 0);
		lblSignInTo.setSize("219px", "24px");
		
		FlexTable flexTable = new FlexTable();
		flexTable.setStyleName("gwt-FlexTable-clear");
		basePanel.add(flexTable, 10, 23);
		
		Label lblUsername = new Label("Username");
		lblUsername.setStyleName("gwt-Label-ocrsWhite");
		//lblUsername.setStyleName("gwt-Label-Login");
		flexTable.setWidget(0, 0, lblUsername);
		
		textBoxUsername = new TextBox();
		textBoxUsername.setFocus(true);
		flexTable.setWidget(0, 1, textBoxUsername);
		
		Label lblPassword = new Label("Password");
		lblPassword.setStyleName("gwt-Label-ocrsWhite");
		//lblPassword.setStyleName("gwt-Label-Login");
		flexTable.setWidget(1, 0, lblPassword);
		
		textBoxPassword = new PasswordTextBox();
		flexTable.setWidget(1, 1, textBoxPassword);
		flexTable.getCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_BOTTOM);
		
		Button button = new Button("Sign In");
		button.setFocus(true);
		button.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if(textBoxUsername.getText().length() == 0 ||
					textBoxPassword.getText().length() == 0	)
				{
					Window.alert("Username or password field empty.");
				
				}
				else
				{
					//if login valid proceed to next page based on permission of user
					if(verifyLoginDetails()){
						
						
					}
				}
			}
		});
		
		flexTable.setWidget(2, 1, button);
		//setStyleName("gwt-Background-Login");
	}

	/**
	 * verifyLoginDetails
	 * make sure username and password are valid
	 * 
	 */
	public boolean verifyLoginDetails()
	{
		//TODO
		return true;
	//	return MiddleMan.loginUser(textBoxUsername.getText(), textBoxPassword.getText() );
	}
	

}
